#ifndef INITRD_FILESYSTEM_H
#define INITRD_FILESYSTEM_H

#include <Globals.h>
#include <Filesystem.h>
#include <File.h>
#include <Directory.h>

typedef struct
{
  u32int nFiles;
} InitrdHeader;

typedef struct
{
  u8int magic;			// Magic number, for error checking.
  s8int name[64];		// File name.
  u32int offset;		// Offset in the initrd that the file starts.
  u32int length;		// Length of the file.
} InitrdFileHeader;

/**
   A specialised filesystem for dealing with the initial ramdisk. The
   ramdisk must be loaded before any programs can be executed. For
   this reason, the initrd driver is inside the kernel.
**/
class InitrdFilesystem
{
public:
  /**
     Constructor, taking a placement address as a parameter.
  **/
  InitrdFilesystem(Address addr);
  
  ~InitrdFilesystem();

  /**
    Returns a filesystem abstraction, representing this object.
  **/
  Filesystem *getFilesystem()
  {
    return filesystem;
  }
  
  /**
    We are a system resource.
  **/
  Resource *resource;

private:
  bool open(int impl, FileDescriptor *fd);
  bool close(int impl, FileDescriptor *fd);
  u32int read(int impl, u32int offset, u32int size, u8int *buffer);
  u32int write(int impl, u32int offset, u32int size, u8int *buffer);
  u32int length(int impl);

  /**
     The initial file header.
  **/
  InitrdHeader *header;

  /**
     Array of file header structures.
  **/
  InitrdFileHeader *fileHeaders;
  
  /**
    The internal filesystem abstraction.
  **/
  Filesystem *filesystem;
  
};


#endif // INITRD_FILESYSTEM_H
